package com.service.gmall.user.comtroller;

import com.service.gmall.common.result.Result;
import com.service.gmall.common.result.ResultCodeEnum;
import com.service.gmall.model.user.UserInfo;
import com.service.gmall.model.vo.user.LoginSuccessVo;
import com.service.gmall.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author alpha
 * @className: UserController
 * @date 2022/9/6 19:58
 * @Description
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    UserInfoService infoService;
    /**
     * 登录
     * @return
     */
    @PostMapping("/passport/login")
    public Result login(@RequestBody UserInfo info) {
        LoginSuccessVo vo = infoService.login(info);
        if (vo != null) {
            return Result.ok(vo);
        }
        return Result.build("", ResultCodeEnum.LOGIN_ERROR);
    }

    /**
     * 退出
     * @return
     */
    @GetMapping("/passport/logout")
    public Result logout(@RequestHeader("token") String token){
        infoService.logout(token);
        return Result.ok();
    }
}
